﻿#region Header
// Copyright 2007-2011, Jerónimo Milea
// 
// This file is part of NetJsWire.
// 
//     NetJsWire is free software: you can redistribute it and/or modify
//     it under the terms of the GNU General Public License as published by
//     the Free Software Foundation, either version 3 of the License, or
//     (at your option) any later version.
// 
//     NetJsWire is distributed in the hope that it will be useful,
//     but WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//     GNU General Public License for more details.
// 
//     You should have received a copy of the GNU General Public License
//     along with NetJsWire.  If not, see <http://www.gnu.org/licenses/>.
#endregion

using System.Windows.Forms;
using NetJsWire.JsonRpcHandler;
using NetJsWire.JsonRpcHandler.Attributes;
using NetJsWire.Widgets.Core;
using NetJsWire.Widgets.Renderers.Core;
using NetJsWire.Widgets.Ui.Layout;

namespace NetJsWire.Widgets.Renderers.Form
{
    [ClassName( "Ext.ux.NCheckBox" )]
    internal class CheckBox : Widget, IRenderer
    {
        protected string _CHECK = "";

        public CheckBox( object baseObject )
            : base( baseObject )
        {
        }

        #region IRenderer Members

        public override void Render()
        {
            if ( !Rendered )
            {
                if ( BaseParent is IWidgetContainer )
                {
                    SetAttribute( ControlNode, "isInContainer", true );
                    SetConstructionProperty( "isInContainer", true );

                    if ( ( ( Ui.Form.CheckBox ) Base ).SendUpdates )
                        SetConstructionProperty( "sendUpdates", ( ( Ui.Form.CheckBox ) Base ).SendUpdates );

                    if ( ( BaseParent as IWidgetContainer ).Layout == LayoutType.Form && !string.IsNullOrEmpty( ( ( Ui.Form.CheckBox ) Base ).FieldLabel ) )
                        SetConstructionProperty( "fieldLabel", ( ( Ui.Form.CheckBox ) Base ).FieldLabel );
                }
                else
                {
                    SetStyleProperty( "position", "absolute" );
                    SetConstructionProperty( "parent", ClientParentToRender );
                }

                EnsureParentNodePosition();

                //_constructorParameters = "\"" + ClientID + "\"";
                SetConstructionProperty( "tabIndex",
                                         ( ( Ui.Form.CheckBox ) Base ).TabIndex > 0
                                             ? ( ( Ui.Form.CheckBox ) Base ).TabIndex
                                             : 0 );
                //SetConstructionProperty("renderTo", ClientParentToRender);
                if ( !( ( Ui.Form.CheckBox ) Base ).AutoSize )
                    SetConstructionProperty( "width", ( ( Control ) Base ).ClientSize.Width );
                SetConstructionProperty( "checked", ( ( Ui.Form.CheckBox ) Base ).Checked );
            }
            base.Render();
        }

        #endregion
    }
}